<script setup lang="ts">
import { request } from '@/api'
import { closeToast, showLoadingToast } from 'vant'
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'

// 获取当前页面对应的路由对象
const route = useRoute()
const router = useRouter()
// 接收 路由传参
const Name: string = route.query.name as string
const myName = ref(Name)
// 改名
const changeName = async () => {
  // showLoadingToast({ message: '加载中...', duration: 0, forbidClick: true })
  const input = document.getElementById('myInput')
  const value = input?.innerText
  try {
    const data = {
      name: value,
    }
    const res = await request.patch<GGResponse<User>>('/v1_0/user/profile', data)
    console.log(res.data.data.name)
    // closeToast()
    router.back()
  } catch (error) {
    router.back()
    console.log(error)
  }
}
</script>

<template>
  <div>
    <input type="text" style="width: 100%" id="myInput" v-model="myName" />
    <van-button
      type="primary"
      block
      style="background-color: #fff; color: blue; border: #fff"
      @click="changeName"
      >提交</van-button
    >
  </div>
</template>
